Skip to content

Propose SIP-34 onActivityItem handler / hook#179

Open
smilingkylan wants to merge 3 commits intomainfrom
kylan/on-activity-item
Open

Propose SIP-34 onActivityItem handler / hook#179
smilingkylan wants to merge 3 commits intomainfrom
kylan/on-activity-item

Conversation

@smilingkylan
Copy link

@smilingkylan smilingkylan commented Oct 27, 2025

Related to issue: MetaMask/snaps#3520

The purpose of this SIP is to add a new Snap lifecycle hook: onActivityItem

(feel free to use your own name for it).

This event will be triggered when someone clicks on an activity item (ie past transaction) and will optionally provide Snap developers with an area (like onTransaction and onSignature) at the bottom of the modal below:

Screenshot 2025-10-27 at 1 47 22 PM

This onActivityItem hook will pass the Snap developer information about the transaction, as well as information about the transactions status (eg confirmed, rejected / failed, pending, etc) which a Snap developer can use to provider insights to end-users


Note

Introduces SIP-34 describing an onActivityItem lifecycle hook for activity items and a new endowment:activity-item-insight permission.

  • SIPs:
    • New: SIPS/sip-34.md
      • Proposes onActivityItem lifecycle hook triggered on activity item (transaction) click, with confirmations and optional origin.
      • Introduces endowment:activity-item-insight permission (allowActivityItemOrigin option) for accessing activity item details.
      • Includes example handler and notes on security, UX, and backward compatibility.

Written by Cursor Bugbot for commit 660de5a. This will update automatically on new commits. Configure here.

@smilingkylan smilingkylan requested review from a team and Montoya as code owners October 27, 2025 20:46
```json
{
"initialPermissions": {
"endowment:activity-item-insight": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop the -item here.

Suggested change
"endowment:activity-item-insight": {
"endowment:activity-insight": {

2. The parameters passed to the `onActivityItem` function should also include information about confirmations for the activity item / transaction

```
import type { OnActivityItemHandler } from "@metamask/snaps-sdk";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a definition for this type?

Comment on lines +33 to +34
// should this be `activityItem` instead or is `Activity` only ever transactions?
// `transaction` param should also include details about tx / block confirmations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should figure this out before merging. 😅


One of the perks of this proposal is that we can more or less mimic the `onTransaction` and `onSignature` handlers. The main two differences will be the following:

1. Different entry-point (I will leave this part to you)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by this?

Copy link
Author

@smilingkylan smilingkylan Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "entry point" I just meant the area in the code / UI where the on_____ hooks into. I expect much of the parameters to be the same as onTransaction and onSignature (transaction, transactionOrigin, chainId), just with some extra information about confirmations and whatever other info developers want. Maybe currentStatus, timestamps (submitted and confirmation time), block number and block hash, info about gas used, transaction hash and nonce,

Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
@smilingkylan
Copy link
Author

smilingkylan commented Mar 9, 2026

I cannot push directly to this branch anymore because I no longer work for MetaMask. Here is the content of what I'd like the ./SIPS/sip-34.md to say. I will also create a new pull request from my forked repo in case you'd prefer that method.

PR from personal fork: #182


sip: 34
title: Activity Item Insights
status: Draft
author: Kylan Hurt (smilingkylan.eth, kylan.hurt@gmail.com)
created: 2025-10-26

Abstract

The purpose of this SIP is to propose the addition of a lifecycle hook, onActivityItem, similar to the onTransaction and onSignature hooks that triggers when the user clicks on a history item (typically a transaction), passing with it parameters related to the transaction.

Motivation

Some web functionality works best when triggered after a financial transaction has occurred. In Web2 some examples may be satisfaction surveys after an online order, an email encouraging users to sign up for a newsletter, or consider purchasing another product related to the one they just bought.

While Web3 may not support communication services like email or text message natively, we can include information and call-to-actions at the point where the user is within the context of the product they just bought: when viewing the completed (or failed) transaction itself. The equivalent in MetaMask is Activity (history) tab of the home screen.

If a user wants to learn more about a past transaction or the smart contract / dapp they interacted with then we can present those sorts of insights to them at the point when they are viewing a previous transaction.

Specification

Formal specifications are written in Typescript. Usage of CAIP-N specifications, where N is a number, are references to Chain Agnostic Improvement Proposals.

Language

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
"OPTIONAL" written in uppercase in this document are to be interpreted as described in RFC 2119

Snap Manifest

This SIP introduces a new permission named endowment:activity-insight. This permission grants a Snap the ability to read details about an activity item (transaction) and optionally the origin from which that transaction originated.

This permission is specified as follows in snap.manifest.json files:

{
  "initialPermissions": {
    "endowment:activity-insight": {}
  }
}

The permission includes an OPTIONAL caveat allowActivityOrigin.
The caveat grants a Snap read-only access to the URL of the dapp that initiated the transaction.
It can be specified as follows:

{
  "initialPermissions": {
    "endowment:activity-insight": {
      "allowActivityOrigin": true
    }
  }
}

Snap Implementation

The following is an example implementation of the API:

import type { OnActivityItemHandler } from "@metamask/snaps-sdk";
import { Box, Heading, Text } from "@metamask/snaps-sdk/jsx";

export const onActivityItem: OnActivityItemHandler = async ({
  transaction,
  chainId,
  transactionOrigin,
  status,
  transactionHash,
  receipt,
}) => {
  const insights = /* Get insights */;
  return {
    content: (
      <Box>
        <Heading>My Activity Item Insights</Heading>
        <Text>Here are the insights:</Text>
        {insights.map((insight) => (
          <Text>{insight.value}</Text>
        ))}
      </Box>
    ),
  };
};

The interface for an onActivityItem handler function's arguments is:

interface OnActivityItemArgs {
  transaction: Transaction;
  chainId: CaipChainId;
  transactionOrigin?: string;
  status: ActivityItemStatus;
  transactionHash?: string;
  transactionType?: string;
  receipt?: ActivityItemReceipt;
  blockNumber?: string;
  blockTimestamp?: string;
  submittedTime?: number;
  error?: { message: string; rpc?: string };
}

transaction - The transaction parameters object. This is intentionally aligned with the transaction argument in onTransaction (see SIP-3), using the same Transaction type from @metamask/snaps-sdk.

chainId - A CAIP-2 chain ID string (e.g. "eip155:1").

transactionOrigin - The URL origin of the dapp that initiated the transaction. The existence of this property is dependent on the allowActivityOrigin caveat.

status - The status of the activity item at the time the user views it. See ActivityItemStatus below.

transactionHash - The on-chain transaction hash, if the transaction was submitted to the network.

transactionType - A string describing the kind of transaction (e.g. "simpleSend", "contractInteraction", "swap", "tokenMethodTransfer"). The set of possible values may expand over time.

receipt - The transaction receipt, available once the transaction has been included in a block. See ActivityItemReceipt below.

blockNumber - The number of the block in which the transaction was included.

blockTimestamp - The timestamp of the block in which the transaction was included.

submittedTime - The Unix epoch timestamp (in milliseconds) at which the transaction was submitted to the network.

error - Error details if the transaction failed or was reverted on-chain.

The ActivityItemStatus type represents the possible states of an activity item as seen in the Activity tab:

type ActivityItemStatus =
  | 'confirmed'  // Successfully mined and included in a block
  | 'failed'     // Reverted on-chain or errored during execution
  | 'submitted'  // Pending in the mempool
  | 'dropped'    // Replaced or dropped from the mempool
  | 'rejected';  // Rejected by the user before submission

The ActivityItemReceipt type contains on-chain execution details returned by the network after the transaction is mined:

interface ActivityItemReceipt {
  blockHash?: string;
  blockNumber?: string;
  effectiveGasPrice?: string;
  gasUsed?: string;
  l1Fee?: string;
  logs?: { address?: string; data?: string; topics?: string }[];
  status?: string;           // "0x1" for success, "0x0" for revert
  transactionIndex?: string;
}

The interface for the return value of an onActivityItem export is:

interface OnActivityItemResponse {
  content: Component | null;
  severity?: SeverityLevel;
}

Security Considerations

The security concerns are very similar to the onTransaction handler (see SIP-3), except that this hook fires on a completed or pending transaction rather than one that is about to be signed. Snap developers MUST NOT assume that the presence of a receipt or transactionHash implies the transaction was successful; the status field SHOULD be used as the authoritative indicator of outcome.

Backwards Compatibility

This SIP introduces a new method and does not modify any existing functionality. Therefore, there are no backwards compatibility concerns.

Copyright

Copyright and related rights waived via CC0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants